<template>
	<view>
		<view class="page">
			<comp-common v-bind="{data:data}" @getUserInfo="getUserInfo" @myLogin="myLogin" @getPhoneNumber="getPhoneNumber" @hideGetCoupon="hideGetCoupon" @closeCouponBox="closeCouponBox" @navigatorClick="navigatorClick"></comp-common>
			<comp-header v-bind="{data:data}" @relevanceError="relevanceError" @relevanceSuccess="relevanceSuccess"></comp-header>
			<view class="body">
				<navbar v-bind="{data:data}" @navigatorClick="navigatorClick"></navbar>
        <view class="after-navber">
            <view style="padding: 0 60upx">
                <view style="padding:80upx 0 48upx;border-bottom: 1upx solid #e3e3e3;margin-bottom: 72upx;text-align: center">
                    <image :src="data.__wxapp_img.system.wechatapp.url" style="width: 200upx;height: 200upx;" v-if="data.__platform=='wx'"></image>
                    <image :src="data.__wxapp_img.system.alipay.url" style="width: 200upx;height: 200upx;" v-else></image>
                </view>
                <view style="font-size: 13pt;margin-bottom: 40upx">申请获取以下权限</view>
                <view style="color: #888;margin-bottom: 88upx">获得你的公开信息（昵称、头像等）</view>
                <button bindgetuserinfo="getUserInfo" @tap="myLogin" class="login-btn" openType="getUserInfo">授权登录</button>
            </view>
        </view>
    </view>
			<comp-footer v-bind="{data:data}"></comp-footer>
		</view>
	</view>
</template>

<script>var myVue = {};
	import navbar from '../../components/common/navbar.vue'
	export default {
		components:{navbar},
		data() {
			return {
				data: {},
			};
		},
		onLoad: function(e) {myVue = this;
        myVue.getApp.page.onLoad(this, e);
    },
		methods: {
			getUserInfo: function(e) {
        var t = this;
        "getUserInfo:ok" == e.detail.errMsg && myVue.getApp.core.login({
            success: function(o) {
                var n = o.code;
                t.unionLogin({
                    code: n,
                    user_info: e.detail.rawData,
                    encrypted_data: e.detail.encryptedData,
                    iv: e.detail.iv,
                    signature: e.detail.signature
                });
            },
            fail: function(e) {}
        });
    },
    myLogin: function() {
        var e = this;
        "my" === myVue.getApp.platform && my.getAuthCode({
            scopes: "auth_user",
            success: function(t) {
                e.unionLogin({
                    code: t.authCode
                });
            }
        });
    },
    unionLogin: function(e) {
			var _this = this;
        myVue.getApp.core.showLoading({
            title: "正在登录",
            mask: !0
        }), myVue.getApp.request({
            url: myVue.getApp.api.passport.login,
            method: "POST",
            data: e,
            success: function(e) {
                if (0 == e.code) {
                    myVue.getApp.setUser(e.data), myVue.getApp.core.setStorageSync(myVue.getApp.const.ACCESS_TOKEN, e.data.access_token), 
                    myVue.getApp.trigger.run(myVue.getApp.trigger.events.login);
                    var t = myVue.getApp.core.getStorageSync(myVue.getApp.const.LOGIN_PRE_PAGE);
                    t && t.route ? myVue.getApp.core.redirectTo({
                        url: "/" + t.route + "?" + myVue.getApp.helper.objectToUrlParams(t.options)
                    }) : myVue.getApp.core.redirectTo({
                        url: "/pages/index/index"
                    });
                } else myVue.getApp.core.showModal({
                    title: "提示",
                    content: e.msg,
                    showCancel: !1
                });
            },
            complete: function() {
                myVue.getApp.core.hideLoading();
            }
        });
    }
		},
	}
</script>

<style scoped>
page {
    background: #fff;
}

.login-btn {
    border: none;
    height: 88upx;
    line-height: 88upx;
    background: #04be01;
    color: #fff;
    font-size: 11pt;
    border-radius: 999upx;
}

.login-btn::after {
    display: none;
}

.login-btn.button-hover {
    box-shadow: inset 0 5upx 30upx rgba(0,0,0,.15);
}
</style>
